package ui.login_ui;

import java.awt.Container;
import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import resultmessage.LoginRM;

public class LoginFrame extends JFrame {
	private int width;
	private int height;
	private String background = "resource\\loginpic\\loginbg.jpg";
	private static final double GOLDEN_RATIO = (Math.sqrt(5) - 1)/2;
	private LoginBackgroundPanel lbp;
 	public LoginFrame(){
		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
		Rectangle rt = ge.getMaximumWindowBounds();
		int w = rt.width;
		int h = rt.height;
		width = w * 2/3;
		height =(int)( width * GOLDEN_RATIO);
		this.setBounds((w - width)/2, (h - height)/2, width, height);
		this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	
		lbp = new LoginBackgroundPanel(background);
		((JPanel)getContentPane()).setOpaque(false);
		lbp.setBounds(0, 0, width, height);
 		this.getLayeredPane().add(lbp,Integer.MIN_VALUE);
 		this.repaint();
	}
	public boolean login(){
		switch(lbp.getLoginResult()){
		case SUCCESS : return true;
		case NO_EXIST_ID : lbp.noExistIDInform();break;
		case WRONG_PASSWORD : lbp.wrongPassword();break;
		case NULL_ID : lbp.nullIDInform();break;
		case NULL_PASSWORD : lbp.nullPassword();break;
		}
		return false;
	}
	public static void main(String[] args){
		LoginFrame lf = new LoginFrame();
		lf.setVisible(true);
	}
}
